package com.acme.ionio.impl;

import com.acme.ionio.FileCopier;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @author Gregory Sobko
 */
public class FileCopierNIO implements FileCopier {
    private static Logger logger = Logger.getLogger(FileCopierNIO.class);

    @Override
    public void copy(File from, File to) throws IOException {
        try (FileChannel fic = new FileInputStream(from).getChannel(); FileChannel foc = new FileOutputStream(to).getChannel()){
            foc.transferFrom(fic, 0, fic.size());
        }
    }
}
